package sort.primarySort;

import sort.template;
import sort.SortCompare;

import java.util.Arrays;

public class Insertion extends template {
    public static void sort(Comparable[] a) {
        int length = a.length;
        for (int i = 1; i < length; i++) {
            for (int j = i; j >= 1 && less(a[j], a[j - 1]); j--) {
                exch(a, j, j - 1);
            }
        }
    }

    public static void main(String[] args) {
        Comparable[] array = SortCompare.getArray(10);
        System.out.println("排序之前:" + Arrays.asList(array));
        sort(array);
        System.out.println("排序之后:" + Arrays.asList(array));
    }
}
